const user = {
	state: {
		user_id: '', // 用户id
		userInfo: {}, // 用户基本信息
		cneeList: [], // 收货人信息列表
	},
	mutations: {
		SET_USER_ID(state, value) {
			state.user_id = value;
		},
		SET_USER_INFO(state, value) {
			state.userInfo = value;
		},
		SET_CNEE_LIST(state, value) {
			state.cneeList = value;
		}
	},
	actions: {
		// 获取用户id并存储
		setUserID({
			commit
		}) {
			uni.login({
				provider: "weixin",
				async success(e) {
					let {
						data
					} = await uni.$http.reqLogin(e.code);
					commit('SET_USER_ID', data.user_id);
				},
				fail() {
					console.log('登录失败')
				}
			})
		},
		// 获取用户基本信息并存储
		async setUserInfo({
			state,
			commit
		}) {
			if (state.user_id) {
				let {
					data
				} = await uni.$http.reqUserInfo(state.user_id);
				commit('SET_USER_INFO', data);
			}
		},
		// 获取收货人信息列表
		async getCneeList({
			state,
			commit
		}) {
			let {
				statusCode,
				data
			} = await uni.$http.reqCneeList(state.user_id);
			if (statusCode == 200) {
				commit('SET_CNEE_LIST', data)
			}
		}
	}
}

export default user
